﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SendSms.aspx.cs" Inherits="UI_SendSms" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>来话宝 <%=FTchina.Library.MasterHelper.ClientTitle %>-短 信 发 送 历 史 查 看 管 理</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link href="/images/style.css" rel="Stylesheet" />
    <script language="javascript" type="text/javascript" src="/js/jiazai.js"></script>
    <script src="/js/introbox.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript" src="/js/jquery-1.3.2.min.js"></script>
    <script language="javascript" type="text/javascript" src="/js/jquery-easyui/jquery.easyui.min.js"></script>
    <script language="javascript" type="text/javascript" src="/js/My97DatePicker/WdatePicker.js"></script>
    <script language="javascript" type="text/javascript" src="/js/pagefunction.js"></script>
    <script language="javascript" type="text/javascript">

        //获取餐桌列表
        function GetDinnerTableByDate() {

            $.get("GetDinnerTableByPcountArea.aspx?t=" + getRandom(100000), { ChkId: 'chkDiningTablezao', ChkValueField: 'DiningTableName', action: 'OnlyList' }, function (data) {
                //alert(data);
                $("#divdinner").html(data);
                AjaxAfterLoad();
            });
        }
        GetDinnerTableByDate(); //获取餐厅列表
        $(document).ready(function () {
            //短信模板
            $("div#smstmp input").css("cursor", "pointer").click(function () {
                SetSms();
            })
            //自选时间
            $("div#selfdate input").css("cursor", "pointer").click(function () {
                SetSms();
            })
            //自选时间
            $("div#selfdate input").css("cursor", "pointer").change(function () {
                SetSms();
            })
            $("#imgfresh").css("cursor", "pointer").click(function () {
                SetSms();
            })
            jQuery.ajaxSetup({ cache: false });
            $("#MakeSMS").click(function () {

                var tc = $("#txbContent").val();
                if (!tc) { alert('请输入短信内容'); return; }
                $.get("/ui/makesms.aspx?t=", { tc: tc }, function (data) {
                    $("#Dspsms").html(data);
                });
            });
            //按选择的group获取客户列表
            function GetGroupListName() {
                var gp = encodeURIComponent($("#ddlpcg").val());

                $.get("/ui/makesms.aspx?t="+getRandom(1000), { gp: gp }, function (data) {

                    $("#pcglistname").html(data);
                });
            };
            GetGroupListName();//访问页面时先获取默认的group名单
            $("#btnGetGroupListName").click(function () {
                GetGroupListName();
            });

            $("#ddlpcg").change(function () {
                GetGroupListName();
            });


            $("#btnpselfselect").click(function () {
                $("#pselfselect").html("");
                $("#pCustomerIDs").val("");
                var src = '/ui/newCustomerselector.aspx?t=' + getRandom(10000);
                var width = "500px";
                var height = "600px";
                var showScroll = "yes";
                var returnValue = window.showModalDialog(src, "", "location:No;status:No;help:No;dialogWidth:" + width + ";dialogHeight:" + height + ";scroll:" + showScroll + ";");

                if (returnValue != null) {
                    var names = returnValue.split("--")[0];
                    var ids = returnValue.split("--")[1];

                    $("#pselfselect").html(names);
                    $("#pCustomerIDs").val(ids);
                }
            });
            $("#btnlistselecct").click(function () {
                $("#pselfselect").html("");
                $("#pCustomerIDs").val("");
                var src = '/ui/CustomerListSelector.aspx?t=' + getRandom(10000);
                var width = "600px";
                var height = "600px";
                var showScroll = "yes";
                var returnValue = window.showModalDialog(src, "", "location:No;status:No;help:No;dialogWidth:" + width + ";dialogHeight:" + height + ";scroll:" + showScroll + ";");

                if (returnValue != null) {
                    var names = returnValue.split("--")[0];
                    var ids = returnValue.split("--")[1];

                    $("#pselfselect").html(names);
                    $("#pCustomerIDs").val(ids);
                }
            });

        });


        function change(gid) {

            if (gid == "group") {
                $("#group").show(); $("#self").hide(); $("#diy").hide();
                $("#smstmp").show(); //短信模板
                $("#MakeSMS").show(); //查看短信示例按钮
                $("#dspsms").show(); //显示短信样例
            }
            if (gid == "self") {
                $("#group").hide(); $("#self").show(); $("#diy").hide();
                $("#smstmp").show(); //短信模板
                $("#MakeSMS").show(); //查看短信示例按钮
                $("#dspsms").show(); //显示短信样例
            }
            if (gid == "diy") {
                $("#group").hide(); $("#self").hide(); $("#diy").show();
                $("#smstmp").hide(); //短信模板
                $("#MakeSMS").hide(); //查看短信示例按钮
                $("#dspsms").hide(); //显示短信样例

            }
        }


        function SetSms() {
            var text = $('input[name="smsactive"]:checked +span ').text();

            var zao = [];
            $('input[name$="chkDiningTablezao"]:checked').each(function () {
                zao.push($(this).val().split("-")[0]);
            });
            var selfdate = $("#txbselfdate").val(); //自选时间
            text = text.replace("{房间名称}", zao).replace("{到店时间}", selfdate);
            $("#txbContent").html(text);

            //短信样例
            $.get("makesms.aspx?t=", { tc: text }, function (data) {
                $("#Dspsms").html(data);
            });
        }


        ///ajax加载的页面需要这样执行事件绑定
        function AjaxAfterLoad() {
            $(function () {
                $('input[name="chkDiningTablezao"]').css("cursor", "pointer").click(function () {
                    SetSms();
                });

            });
        }
    </script>
</head>
<body style="overflow-x: hidden">
    <form id="form1" runat="server">
    <div>
        <table width="100%" class="tableBorder" border='1' cellspacing="0" style="border-collapse: collapse;"
            bgcolor="#ffffff" bordercolor="#cccccc">
            <tr align="center" valign="middle">
                <th height="22" colspan="3">
                    发 送 短 信
                </th>
            </tr>
            <tr>
                <td width="100px">
                </td>
                <td>
                    <input type="radio" onclick="change('self')" value="self" name="ChkType" checked="checked" />从客户列表选择
                    <input type="radio" onclick="change('group')" value="group" name="ChkType" />按客户级别群发
                    <input type="radio" onclick="change('diy')" value="diy" name="ChkType" />按手机号码
                </td>
            </tr>
            <tr id="self">
                <td width="100px">
                    按自选客户发送
                </td>
                <td>
                    <input type="button" class="btn" id="btnpselfselect" value="按级别树选取客户" />
                    <input type="button" class="btn" id="btnlistselecct" value="按列表选取客户" />
                    <input type="text" id="pCustomerIDs" name="pCustomerIDs" value="" style="display: none" />
                    <div id="pselfselect">
                    </div>
                </td>
            </tr>
            <tr id="group" style="display: none;">
                <td width="100px">
                    按客户级别群发
                </td>
                <td>
                    <asp:DropDownList runat="server" ID="ddlpcg">
                    </asp:DropDownList>
                    <input type="button" class="btn" id="btnGetGroupListName" value="获取所选分组名单" />
                    <div id="pcglistname">
                    </div>
                </td>
            </tr>
            <tr id="diy" style="display: none;">
                <td width="100px">
                    接收人手机号
                </td>
                <td>
                    <asp:TextBox runat="server" ID="txbTargets" Width="300px" Height="100px" TextMode="MultiLine"></asp:TextBox>多个手机号请用英文逗号分开
                </td>
            </tr>
            <tr id="smstmp">
                <td width="100px">
                    快速输入
                </td>
                <td>
                    <table width='100%' valign='top' align='left' cellpadding="0" border='1' cellspacing='0'
                        style='border-collapse: collapse;' bordercolor='#cccccc'>
                        <tr>
                            <td>
                                模版
                            </td>
                            <td>
                                <div id="smstmp">
                                    <asp:Literal runat="server" ID="litsms"></asp:Literal>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                {到店时间}
                            </td>
                            <td>
                                <div id="selfdate">
                                    <input type="text" id="txbselfdate" onclick="WdatePicker({onpicked: function () { SetSms(); },isShowClear:true,readOnly:true,dateFmt:'M月dd日HH:mm'});" />
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                {房间名称}
                            </td>
                            <td>
                                <div id="divdinner">
                                </div>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    短信内容
                </td>
                <td>
                    <span id="info">请在下面输入您的文字：</span><img src="/images/refresh.ico" title='header=[提示] body=[单击可以手动刷新，快速格式化短信内容]'
                        id="imgfresh" height="16" onclick="javascript:SetSms()" /><br>
                    <asp:TextBox runat="server" ID="txbContent" Width="300px" Height="200px" TextMode="MultiLine"></asp:TextBox>
                    <br>
                    <input type="button" id="MakeSMS" name="MakeSMS" class="btn" value="查看短信样例" /><span
                        style="color: Gray">客户手机收到的短信内容</span>
                    <div id="Dspsms">
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                    <asp:Button runat="server" ID="btnOk" Text="确定发送" OnClick="btnOk_Click" CssClass="btn" />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
